package com.newdjk.newdoctor.ui;


import android.content.Intent;
import android.os.Bundle;

import android.view.View;
import android.view.Window;
import android.view.WindowManager;


import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.newdjk.newdoctor.R;
import com.newdjk.newdoctor.base.BaseAppcompatActivity;
import com.newdjk.newdoctor.fragment.PictureSlideFragment;
import com.newdjk.newdoctor.utils.Contants;
import com.newdjk.newdoctor.view.ImageOriginPager;
import com.newdjk.newdoctor.view.ViewPagerFixed;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class PictureViewerActivity extends BaseAppcompatActivity {
    @BindView(R.id.viewpager)
    ViewPagerFixed viewpager;
    private List<String> mUrlList; /*所有图片url*/
    private int mPicPosition; /*图片位置*/


    @Override
    public void onPointerCaptureChanged(boolean hasCapture) {

    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.picture_viewer);
        ButterKnife.bind(this);
        setDarkStatusWhite(true);
        Intent intent = getIntent();
        Bundle bundle = intent.getExtras();
        mUrlList = bundle.getStringArrayList("pic_all");
        mPicPosition = bundle.getInt("pic_position");
        viewpager.setAdapter(new PictureSlidePagerAdapter(getSupportFragmentManager()));
        viewpager.setCurrentItem(mPicPosition);
    }

    private class PictureSlidePagerAdapter extends FragmentStatePagerAdapter {
        public PictureSlidePagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return PictureSlideFragment.newInstance(mUrlList.get(position));
        }

        @Override
        public int getCount() {
            if (mUrlList != null) {
                return mUrlList.size();
            }
            return 0;
        }
    }


}
